<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://eureka.yigolden.net/stringutils/sutaglib/1.0" prefix="su"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
	<title>出售室友</title>

  <!-- Bootstrap -->
    <link href="<%=request.getContextPath()%>/static/css/bootstrap.min.css" rel="stylesheet">
    <link href="<%=request.getContextPath()%>/static/css/bootstrap-theme.min.css" rel="stylesheet">
    <link href="<%=request.getContextPath()%>/static/css/jumbotron.css" rel="stylesheet">
    
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="<%=request.getContextPath()%>/static/js/html5shiv.min.js"></script>
      <script src="<%=request.getContextPath()%>/static/js/respond.min.js"></script>
    <![endif]-->
    
    <script type="text/javascript">
    
    function submitForm(itemid){
    	
    	var formbyid=document.getElementById(itemid);
    	formbyid.submit();
    }
    
    </script>
     <script src="<%=request.getContextPath()%>/static/js/jquery.min.js"></script>
</head>
<body>
<jsp:include page="../Common/navHeader.jsp"></jsp:include>

<div class="container">

	  <br>
	  <br>       
      <br/>   
      
	  <div class="row">
      <div class="col-sm-1"></div><!--左侧不用-->

	  <% request.setAttribute("tag", "myroommates"); %>
	  <jsp:include page="navLeftBar.jsp"></jsp:include>

      <div class="col-sm-8 col-xs-12">
	  
		  <c:set var="i" value="0" />
		      <c:if test="${roommates ne null }">         
		  
				  <div class="table-responsive">
				    <table class="table table-hover table-stripped">
					  <tr style="background:aliceblue">
					    <td>用户名</td>
					    <td>就读院校</td>
					    <td>所在寝室</td>
					  </tr>
					  
					  <c:forEach var="item" items="${roommates}">
					  
						<tr>
						  <td><a href="<%=request.getContextPath() %>/Account/ShowUserDetailInfo?userid=${item.userid }" target="_blank">${fn:escapeXml(item.username)}</a></td>
						  <td><a href="<%=request.getContextPath() %>/Show/ShowUniversityByDomitory?universityid=${item.universityid}" target="_blank">${fn:escapeXml(item.universityname)}</a></td>
						  <td>${fn:escapeXml(item.domitoryid) }</td>
						</tr>
					  </c:forEach>
					</table>
				  </div>
			   
			  <br/>
		      </c:if>
		      
		      <c:if test="${roommates eq null }">  
		        <div class="alert alert-warning" role="alert">
		           	不好意思，您暂时还没有室友！
		        </div>
		      </c:if>

      <br/>

      </div>
      <div class="col-sm-1"></div><!--右侧不用-->
    </div>
 
    <jsp:include page="../Common/Footer.jsp"></jsp:include>

</div>

 <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="<%=request.getContextPath()%>/static/js/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="<%=request.getContextPath()%>/static/js/bootstrap.min.js"></script>

	<script>
	window.getroommategroupBusy=false;
	$(document).ready(function() {
		
	    $("a.getroommategroup").click(function() {
	    	
	    	if(window.getroommategroupBusy)
	    		window.getroommategroupBusy=false;
	    	window.getroommategroupBusy=true;
    		
    		$("a.getroommategroup").addClass("disabled");
    		var universityid=$(this).data("university");
    		var domitoryid=$(this).data("domitory");
    		var postData={
    				universityid:universityid,
    				domitoryid:domitoryid
    		};
    		
    		
    		$.ajax({
    			method:"POST",
    			url:"<%=request.getContextPath()%>/Roommate/SellRoommate",
    			contentType:"application/json",
    			data:JSON.stringify(postData),
    			dataType:"json",
    			success:function(data){
    				if(data.status==0){
    					alert("添加成功！");
    					
    					var id=$(this).attr("id");
    					$("div#"+id).html=' <div class="table-responsive">'
    					    +'<table class="table table-hover table-stripped">'
						    +'  <tr style="background:aliceblue">'
						    +'   <td style="min-width:60px">机构名</td>'
						    +'   <td>宿舍号</td>'
						    +'   <td>用户名</td>'
						    +'  </tr>'
						    +'  <c:forEach var="item" items="${data.allocations}">'
							+'   <tr>'
							+'     <td>${fn:escapeXml(item.universityname) }</td>'
							+'     <td>${fn:escapeXml(item.domitoryid) }</td>'
							+'     <td><a href="<%=request.getContextPath() %>/Account/ShowUserDetailInfo?userid=${item.userid }" target="_blank">${fn:escapeXml(item.username) }</a></td>'
							+'   </tr>'
						    +' </c:forEach>'
					        +'</table>'
			                +'</div>';
    				}else{
    					alert(data.message);
    				}
    			},
    			error:function(){
    				alert("服务器连接失败！");
    			},
    			complete:function(){
    				$("a.getroommategroup").removeClass("disabled");
    				window.getroommategroupBusy=false;
    			}
    		});
	    	return false;
	    });
	});

	</script>
</body>
</html>